//
//  ST_EditDailyMomentImageItemView.swift
//  btvideo
//
//  Created by mac on 2020/7/23.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit

class ST_EditDailyMomentImageItemView: UIControl {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.cornerRadius = 10
        
        self.addSubview(cover_image_view)
        cover_image_view.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        
        self.addSubview(delete_btn)
        delete_btn.snp.makeConstraints { (make) in
            make.width.height.equalTo(17+5)
            make.right.top.equalToSuperview()
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    fileprivate lazy var cover_image_view:UIImageView = {
        let control = UIImageView()
        control.contentMode = .scaleAspectFill
        control.cornerRadius = 10
        return control
    }()
    
    fileprivate lazy var delete_btn:UIButton = {
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.setImageForAllStates(ST_ImageUtils.imageName("media_delete_small")!)
        control.addTarget(self, action: #selector(delete_handle), for: UIControl.Event.touchUpInside)
        return control
    }()
    
    var clear_closure:(((identifier:String,image:UIImage))->())?
    
    
    var picture:(identifier:String,image:UIImage)?{
        didSet{
            cover_image_view.image = picture?.image
        }
    }
}

extension ST_EditDailyMomentImageItemView{
   
    @objc fileprivate func delete_handle(){
        
        guard let p = picture else{
            return
        }
        clear_closure?(p)
    }
}
